﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using QMERP.Domain.Entities;

namespace QMERP.Infrastructure.EFCore.Mappings
{
    public class LeaveStockOrderMapping : IEntityTypeConfiguration<LeaveStockOrder>
    {
        public void Configure(EntityTypeBuilder<LeaveStockOrder> builder)
        {
            builder.HasQueryFilter(x => x.IsEnable);
            builder.Property(x => x.Number).HasMaxLength(30);
            builder.Property(x => x.BusinessOrderId).IsRequired(false);
            builder.Property(x => x.BusinessOrderNumber).IsRequired(false).HasMaxLength(30);
            builder.Property(x => x.BusinessOrderType).IsRequired(false).HasMaxLength(50);
            builder.Property(x => x.BusinessType).HasMaxLength(50);
            builder.Property(x => x.LeaveStockWay).IsRequired(false).HasMaxLength(200);
            builder.Property(x => x.Status).HasMaxLength(50);
            builder.Property(x => x.CheckedBy).IsRequired(false);
            builder.Property(x => x.CheckedByName).HasMaxLength(50).IsRequired(false);
            builder.Property(x => x.CheckedOn).IsRequired(false).HasColumnType("datetime");
            builder.Property(x => x.Remark).IsRequired(false).HasMaxLength(500);

            builder.Property(x => x.ShipmentLogId).IsRequired(false);

            builder.HasIndex(x => x.Id);
            builder.HasIndex(x => x.Number);
            builder.HasIndex(x => x.BusinessOrderId);
            builder.HasIndex(x => x.BusinessOrderNumber);
            builder.HasIndex(x => x.BusinessOrderType);
            builder.HasIndex(x => x.BusinessType);
            builder.HasIndex(x => x.Status);
            builder.HasIndex(x => x.CreatedOn).IsDescending();
            builder.HasIndex(x => x.CheckedOn).IsDescending();
            builder.HasIndex(x => x.ShipmentLogId);
        }
    }
}
